package demo2;

public class Test1 {
     private static boolean isQuit = false ;
    public static void main(String[] args) throws InterruptedException {
         //boolean isQuit = false ;  main的局部变量
        Thread t1 = new Thread(()->{
            while (!isQuit){
                System.out.println("run正在执行中");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("run执行完成");
        });
         t1.start();
        System.out.println("线程开始执行");
        System.out.println("5秒后线程终止");
         Thread.sleep(5000);
        isQuit = true ;
        System.out.println("设置isQuit 为true");

    }
}
